home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / DYNREC.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  87 lines

  1.                                         (* Chapter 12 - Program 2 *)
  2. MODULE DynRec;
  3.  
  4. FROM InOut   IMPORT WriteString, Write, WriteLn;
  5. FROM Storage IMPORT ALLOCATE, DEALLOCATE;
  6. FROM SYSTEM  IMPORT TSIZE;
  7.  
  8. CONST  NumberOfFriends = 50;
  9.  
  10. TYPE   FullName = RECORD
  11.          FirstName : ARRAY[0..12] OF CHAR;
  12.          Initial   : CHAR;
  13.          LastName  : ARRAY[0..15] OF CHAR;
  14.        END;
  15.  
  16.        Date = RECORD
  17.          Day   : CARDINAL;
  18.          Month : CARDINAL;
  19.          Year  : CARDINAL;
  20.        END;
  21.  
  22.        PersonID = POINTER TO Person;
  23.        Person = RECORD
  24.          Name      : FullName;
  25.          City      : ARRAY[0..15] OF CHAR;
  26.          State     : ARRAY[0..3] OF CHAR;
  27.          BirthDay  : Date;
  28.        END;
  29.  
  30. VAR   Friend  : ARRAY[1..NumberOfFriends] OF PersonID;
  31.       Self, Mother, Father : PersonID;
  32.       Temp    : Person;
  33.       Index   : CARDINAL;
  34.  
  35. BEGIN  (* Main program *)
  36.    ALLOCATE(Self,TSIZE(Person));    (* Create a dynamically
  37.                                                 allocated variable *)
  38.    Self^.Name.FirstName := "Charley ";
  39.    Self^.Name.Initial := 'Z';
  40.    Self^.Name.LastName := " Brown";
  41.    WITH Self^ DO
  42.       City := "Anywhere";
  43.       State := "CA";
  44.       BirthDay.Day := 17;
  45.       WITH BirthDay DO
  46.          Month := 7;
  47.          Year := 1938;
  48.       END;
  49.    END;     (* All data for Self is now defined *)
  50.  
  51.    ALLOCATE(Mother,TSIZE(Person));
  52.    Mother := Self;
  53.  
  54.    ALLOCATE(Father,TSIZE(Person));
  55.    Father^ := Mother^;
  56.  
  57.    FOR Index := 1 TO NumberOfFriends DO
  58.       ALLOCATE(Friend[Index],TSIZE(Person));
  59.       Friend[Index]^ := Mother^;
  60.    END;
  61.  
  62.    Temp := Friend[27]^;
  63.    WriteString(Temp.Name.FirstName);
  64.    Write(Self^.Name.Initial);
  65.    WriteString(Mother^.Name.LastName);
  66.    WriteLn;
  67.  
  68.    DEALLOCATE(Self,TSIZE(Person));
  69. (* DEALLOCATE(Mother,TSIZE(Person)); Since Mother is lost, it cannot
  70.                                                     be disposed of *)
  71.    DEALLOCATE(Father,TSIZE(Person));
  72.    FOR Index := 1 TO NumberOfFriends DO
  73.       DEALLOCATE(Friend[Index],TSIZE(Person));
  74.    END;
  75.  
  76. END DynRec.
  77.  
  78.  
  79.  
  80.  
  81. (* Result of execution
  82.  
  83. Charley Z Brown
  84.  
  85. *)
  86.  
  87.